package fudan.se.project.controller.conference.action;


import fudan.se.project.controller.request.DatesModifyRequest;
import fudan.se.project.controller.request.OnlyIdPropertyRequest;
import fudan.se.project.controller.request.PcMemberInviteRequest;
import fudan.se.project.controller.request.ReviewStartRequest;
import fudan.se.project.service.advanced.conference.action.ChairActionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@Slf4j
@RestController
@RequestMapping("/user/conference/chair")
public class ChairActionController {

    private final ChairActionService chairActionService;

    @Autowired
    public ChairActionController(ChairActionService chairActionService) {
        this.chairActionService = chairActionService;
    }

    @GetMapping("/searchPcMembers")
    public ResponseEntity<?> searchPcMembers(
            @RequestParam long id,
            @RequestParam @NotNull @NotBlank String realname
    ) {
        return chairActionService.searchPcMembers(id, realname);
    }


    @PostMapping("/invitePcMembers")
    public ResponseEntity<?> invitePcMember(@Validated @RequestBody PcMemberInviteRequest request) {

        return chairActionService.invitePcMembers(request);
    }

    @PostMapping("/openSubmission")
    public ResponseEntity<?> openSubmission(@Validated @RequestBody OnlyIdPropertyRequest request) {

        return chairActionService.openSubmission(request);
    }

    @PostMapping("/startReview")
    public ResponseEntity<?> startReview(@Validated @RequestBody ReviewStartRequest request) {

        return chairActionService.startReview(request);
    }

    @PostMapping("/releaseResult")
    public ResponseEntity<?> releaseResult(@Validated @RequestBody OnlyIdPropertyRequest request) {

        return chairActionService.releaseResult(request);
    }

    @PostMapping("/modifyDates")
    public ResponseEntity<?> modifyDates(@Validated @RequestBody DatesModifyRequest request) {

        return chairActionService.modifyDates(request);
    }

    @PostMapping("/releaseFinal")
    public ResponseEntity<?> releaseFinal(@Validated @RequestBody OnlyIdPropertyRequest request) {

        log.info("Chair release final results for conference:" + request.getId());
        return chairActionService.releaseFinal(request);
    }

}
